package twoRegInstructions;

import java.io.FileNotFoundException;
import java.io.IOException;

import main.MIPSSimulator;



public class Lw extends MIPSTwoRegInstruction {
	public Lw(String input) throws FileNotFoundException, IOException {
		super(input);
		myName = "lw";
	}

	@Override
	public void execute() {
		int regTwo = MIPSSimulator.myRegisters.get(myRegisterTwo);
		int regTwoAddress = MIPSSimulator.addressConversion(regTwo);
		int firstBytes = MIPSSimulator.myStack[regTwoAddress + myImmediateValue] << 24;
		int secondBytes = MIPSSimulator.myStack[regTwoAddress + myImmediateValue + 1] << 16;
		int thirdBytes = MIPSSimulator.myStack[regTwoAddress + myImmediateValue + 2] << 8;
		int fourthBytes = MIPSSimulator.myStack[regTwoAddress + myImmediateValue + 3];
		int extractedWord = firstBytes + secondBytes + thirdBytes + fourthBytes;
		MIPSSimulator.myRegisters.put(myRegisterOne, extractedWord);
	}
	
	public String toString(){
		return myName + " " + myRegisterOne +", " + myImmediateValueString + "(" + myRegisterTwo + ")";
	}
}
